package com.controller;

import com.pojo.PurchaseChild;
import com.pojo.PurchaseMaster;
import com.service.PurchaseChildService;
import com.service.PurchaseMasterService;
import com.util.Pager;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("procurement/orderGenerate")
public class PurchaseMasterHandler {
    @Resource
    private PurchaseMasterService purchaseMasterService;
    @RequestMapping("/searchByPurchaseMaster")
    @ResponseBody
    public Pager<PurchaseMaster> searchByPurchaseMaster(){
        return purchaseMasterService.searchByPurchaseMaster();
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(PurchaseMaster purchaseMaster){
        String msg="生成订单失败！";
       int i= purchaseMasterService.update(purchaseMaster);
        if(i>0){
            msg="订单生成成功！";
        }
        return msg;
    }


    @RequestMapping("/update1")
    @ResponseBody
    public String update1(PurchaseMaster purchaseMaster){
        String msg="审核失败！";
        int i= purchaseMasterService.update(purchaseMaster);
        if(i>0){
            msg="审核成功！";
        }
        return msg;
    }

    @Resource
    private PurchaseChildService purchaseChildService;
    @RequestMapping("/PurchaseMasterTo")
    public String PurchaseMasterTo(String id, Model model){
 //       PurchaseMaster purchaseMaster =purchaseMasterService.get(id);
        List<PurchaseChild> childList=purchaseChildService.list(id);
//        model.addAttribute("master",purchaseMaster);
        model.addAttribute("child",childList);

        return "procurement/child";
    }

    @RequestMapping("/shenhe")
    public String shenhe(String id, Model model){
        PurchaseMaster purchaseMaster =purchaseMasterService.get(id);
        List<PurchaseChild> childList=purchaseChildService.list(id);
        model.addAttribute("master",purchaseMaster);
        model.addAttribute("child",childList);

        return "procurement/shenhe";
    }

}
